package com.b2c.controller;

import java.util.List;
import java.util.Map;

import com.b2c.membrer.MembersEntity;
import com.b2c.MembersService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import utils.PageUtils;
import utils.Query;
import utils.R;


/**
 * 
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2017-10-11 05:33:23
 */
@RestController
@RequestMapping("/generator/members")
public class MembersController {
	@Autowired
	private MembersService membersService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
		params.put("page","1");
		params.put("limit","10");
        Query query = new Query(params);

		List<MembersEntity> membersList = membersService.queryList(query);
		int total = membersService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(membersList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Integer id){
		MembersEntity members = membersService.queryObject(id);
		
		return R.ok().put("members", members);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody MembersEntity members){
		membersService.save(members);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody MembersEntity members){
		membersService.update(members);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Integer[] ids){
		membersService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
